package core.tool.bpe.action;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.dom4j.Element;

import core.tool.bpe.Action;
import core.tool.bpe.ActionType;
import core.tool.bpe.BpeContext;
import core.tool.io.FileHelper;
import core.tool.xml.dom4j.jaxb.XmlHelper;
@ActionType("COPY_FILE")
public class CopyDocumentsAction extends Action{

	@Override
	protected boolean execute(BpeContext bpeContext) {
		try {
			Map<String, String> copyMap=new HashMap<String, String>();
			List<Element> list=XmlHelper.selectSingleElements(bpeContext.getElement(), "CopyFiles/CopyFile");
			for(Element temp:list) {
				String key=XmlHelper.getElementAttribute(temp, "sourceDir");
				String value=XmlHelper.getElementAttribute(temp, "targetDir");
				copyMap.put(key, value);
			}		
			FileHelper.copyFile(copyMap);
		} catch (IOException e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}
	
}
